package com.agnes.okhttp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.agnes.okhttp.lib.callback.JACallback;
import com.agnes.okhttp.lib.callback.JOCallback;

import org.json.JSONArray;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // test EntityCallback
//        EntityCallback<UserEntity> callback = new EntityCallback<UserEntity>(this) {
//            @Override
//            public void onSuccess(String msg, UserEntity data) {
//                Log.e("Main==>>", data.toString());
//            }
//        };
        JOCallback callback = new JOCallback(this) {
            @Override
            public void onSuccess(String msg, JSONObject data) {
                Log.e("Main==>>",data.toString() );
            }
        };


        String response = "{\"userAreaIds\":null,\"error\":null,\"message\":null,\"devChangCnt\":0,\"result\":0,\"uid\":0,\"userName\":null,\"serverscenterId\":null,\"position\":null,\"downLoadAppUrl\":null,\"fgyIdUrl\":null,\"mobile\":null,\"userPhoto\":\"\"}";
        callback.onResponse(response, 12);


        // test EntityListCallback
//        EntityListCallback<UserEntity> callback2 = new EntityListCallback<UserEntity>(this) {
//
//            @Override
//            public void onSuccess(String msg, List<UserEntity> data) {
//                Log.e("Main==>>", data.toString()+"\n");
//            }
//        };

        JACallback callback2 = new JACallback(this) {

            @Override
            public void onSuccess(String msg, JSONArray data) {
                Log.e("Main==>>", data.toString()+"\n");
            }
        };
        String response2 = "{\"message\":\"\",\"result\":0,\"userList\":[{\"uid\":0,\"userName\":zs},{\"uid\":1,\"userName\":ls},{\"uid\":2,\"userName\":ww}]}";
        callback2.onResponse(response2, 13);

        //ce
//        OkUtils.getInstance().post("http://www.baidu.com", null, new StringCallback() {
//            @Override
//            public void onError(Call call, Exception e, int id) {
//                String d = e.getMessage();
//            }
//
//            @Override
//            public void onResponse(String response, int id) {
//
//            }
//        });


    }
}
